<?php

/**
 * OrderModel 模型
 * Class OrderModel
 */
class OrderModel extends BaseModel
{

    public $tableName = "order";
    public $errMsg = '';

    static private $_singleton;

    public function __construct()
    {
        parent::__construct($this->tableName);
    }

    static public function getSingleton()
    {
        if (!self::$_singleton) {
            self::$_singleton = new static();
        }

        return self::$_singleton;
    }

    static public $statusText = [
        '0' => '待支付',
        '1' => '已支付',
        '2' => '配送中',
        '3' => '已完成',
        '4' => '超时自动取消',
        '5' => '用户取消',
        '6' => '系统强制取消',
        '7' => '申请退款',
        '8' => '无法退款',
        '9' => '已退款',
    ];

    static public $backMoneyText = [
        1   => '我要重新下单',
        2   => '不想要了',
        3   => '不方便收货',
        4   => '等终极促销',
        5   => '其他'
    ];

    public function add($data)
    {
        try {
            $selfModel = static::getSingleton();
            return $selfModel->insert([
                'order_no'  => $data['order_no'],
                'user_id'   => $data['user_id'],
                'shop_id'   => $data['shop_id'],
                'buy_num_total'   => $data['buy_num_total'],
                'status'    => $data['status'],
                'total_money'   => $data['total_money'],
                'total_money_pro'   => $data['total_money_pro'],
                'kpi_point'         => $data['kpi_point'],
                'discount_money'   => isset($data['discount_money'])? $data['discount_money']: 0,
                'discount_point'   => isset($data['discount_point'])? $data['discount_point']: 0,
                'express_type'      => $data['express_type'],
                'express_money'      => $data['express_money'],
                'address_id'        => $data['address_id'],
                'address_user_name' => $data['address_user_name'],
                'address_moble'     => $data['address_moble'],
                'address_text'      => $data['address_text'],
                'create_time'       => isset($data['create_time'])? $data['create_time']: time()
            ]);
        } catch (Exception $e) {
            $this->errMsg = $e->getMessage();
            return false;
        }
    }

    //支付成功回调
    public function paySuccess($order_no){
        //更新订单状态

        //增加冻结积分

        //增加积分记录

        //业绩更新
    }

}